﻿using System;
using System.Linq;
using StreetPacMan.Server.Facade;

namespace StreetPacMan.Server.Rules.PlayerLocationChangeRules
{
    public class ChangeGameStateFromSuperPacManToNormalIfTimeOverRule : IHandlePlayerLocationChangedRule
    {
        public void Handle(PacManDataContext dataContext, ServerPollParameters serverPollParameters, ref bool shouldContinueHandling)
        {
            var game = dataContext.Players.Where(x => x.Id == serverPollParameters.EntityId).Single().Game;
            if(game.StateEnum==GameState.SuperPacMan && 
               game.StateChangeTime < DateTime.Now.AddMinutes(-2))
            {
                game.StateEnum = GameState.Started;
                game.StateChangeTime = DateTime.Now;
                dataContext.AddGameEvent(EventType.GameStateIsNormalPacMan, "2 Minutes passed, PacMan is vulnerable again",0,game.Id);
            }
        }
    }
}